import time

from week3.Base.Base import Base
from selenium.webdriver.common.by import By
from week3.Tools.Tools import Tools
import logging
class Page(Base):
    Tools().log()
    # 1.点击登录
    logging.info('login')
    bd_login_loc = (By.XPATH,'//*[@id="s-top-loginbtn"]')
    def bd_login(self):
        self.click(self.bd_login_loc)
    # 2.输入账号
    logging.info('username')
    username_loc = (By.NAME,'userName')
    def username(self):
        self.send_keys(self.username_loc,'19064013675')
    # 3.输入密码
    logging.info('password')
    password_loc = (By.ID,'TANGRAM__PSP_11__password')
    def password(self):
        self.send_keys(self.password_loc,'zhang185050.')
    # 4 勾选协议
    logging.info('xy')
    xy_loc = (By.XPATH,'//*[@id="TANGRAM__PSP_11__isAgree"]')
    def xy(self):
        self.click(self.xy_loc)
    # 5.点击登录
    login_button = (By.XPATH,'//*[@id="TANGRAM__PSP_11__submit"]')
    def login(self):
        self.click(self.login_button)

    # 断言1 登录
    dy1_loc = (By.XPATH,'//*[@id="s-top-loginbtn"]')
    def dy1(self):
        return self.text(self.dy1_loc)
    # 断言2 账号登录
    dy2_loc = (By.XPATH,'//*[@id="TANGRAM__PSP_11__changePwdCodeItem"]')
    def dy2(self):
        return self.text(self.dy2_loc)
    # 断言3 登录成功后
    dy3_loc = (By.XPATH,'//*[@id="s-top-username"]/span[2]')
    def dy3(self):
        return self.text(self.dy3())
    def badu_login_001(self):
        self.open_url('https://www.baidu.com/')
        print(self.dy1())
        try:
            assert '登录' == self.dy1()
        except Exception as e:
            print(e)
            self.driver.save_screenshot('a.img')
        self.bd_login()
        print(self.dy2())
        try:
            assert '账号登录' == self.dy2()
        except Exception as e:
            print(e)
            self.driver.save_screenshot('b.img')
        self.username()
        self.password()
        self.xy()
        self.login()
        time.sleep(15)


